package org.teachertools.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import org.teachertools.data.Eleve;

public class CompetenceValidator implements Validator {

    @SuppressWarnings("unchecked")
    @Override
    public boolean supports(Class clazz) {
        return Eleve.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmpty(errors, "categorie", "error.form.required", new String[] { "nom" });
        ValidationUtils.rejectIfEmpty(errors, "categorie.matiere", "error.form.required", new String[] { "nom" });
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nom", "error.form.required", new String[] { "nom" });
    }
}
